<%--
  Created by IntelliJ IDEA.
  User: Elle
  Date: 2022/12/26
  Time: 8:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
  <head>
    <title>显示列表</title>
  </head>
  <body>
<%--  <c:if test="${personList == null}">--%>
<%--    <c:redirect url="/do/list"></c:redirect>--%>
<%--  </c:if>--%>
<div>
    <table border="1px solid">
      <tr>
        <th>编号</th>
        <th>名称</th>
        <th>性别</th>
        <th>年龄</th>
        <th>等级</th>
        <th>部门</th>
        <th>操作</th>
      </tr>
      <c:forEach var="tmp" items="${requestScope.personList}">
        <tr>
          <td>${tmp.id }</td>
          <td>${tmp.name }</td>
          <td>${tmp.sex }</td>
          <td>${tmp.age }</td>
          <td>${tmp.rank }</td>
          <td>${tmp.department }</td>
          <td>
            <a href="javascript:void(0)" onclick="del(this,${tmp.id })">删除</a>
          </td>
        </tr>
      </c:forEach>
    </table>
    <button onclick="add()">添加员工</button>
</div>
  </body>
  <script src="js/jquery.js"></script>
<script>
  $(function(){
    $("tr:odd").css("background-color","red");
  });
  function del(obj,id) {
    var isDel = confirm("您确定删除吗？");
    if(isDel){
      //删除
      $.ajax({
        url:"PersonDelServlet", //地址
        data:{"id":id}, //传递的参数
        success:function (data) { //成功，服务器正确==>out输出的内容
          console.log(data);
          if(data.trim()=="ok"){
            alert('删除成功!');
            $(obj).parents("tr").remove();
          }else {
            alert('删除失败!');
          }
        }
      });
    }
  }

  function add() {
    location.href='add.jsp';
  }


</script>




</html>
